package io.lkt.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.Query;
import io.lkt.commons.dynamic.datasource.annotation.DataSource;
import io.lkt.modules.sys.dao.BMessageLinkDao;
import io.lkt.modules.sys.entity.BMessageLinkEntity;
import io.lkt.modules.sys.service.BMessageLinkService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Service("bMessageLinkService")
public class BMessageLinkServiceImpl extends ServiceImpl<BMessageLinkDao, BMessageLinkEntity> implements BMessageLinkService {

    @Resource
    BMessageLinkDao bMessageLinkDao;

    @Override
    @DataSource("master")
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<BMessageLinkEntity> page = this.page(
                new Query<BMessageLinkEntity>().getPage(params),
                new QueryWrapper<BMessageLinkEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    @DataSource("master")
    public List<BMessageLinkEntity> queryAll() {
        QueryWrapper<BMessageLinkEntity> queryWrapper = new QueryWrapper();
//        QueryWrapper<BMessageLinkEntity> queryWrapper2 = Wrappers.<BMessageLinkEntity>query();

        queryWrapper.select("id", "gzh_code", "link_name", "link_url")
                .eq("status", 1)
                .orderByAsc("order_num", "id");

        List<BMessageLinkEntity> temporary = bMessageLinkDao.selectList(queryWrapper);

        return temporary;
    }

}
